﻿//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Text;

//namespace ArtMath.Helper
//{
//    / <summary>
//    / 样条曲线
//    / </summary>
//    public class Spline
//    {
//        public int GeneratePointsCountBetween2SamplePoints = 1;
//        public double Tension = 0;
//        public PointD StartControlPoint = new PointD(), StartPoint = new PointD(),
//            EndControlPoint = new PointD(), EndPoint = new PointD();
//        List<PointD> controlPoints = new List<PointD>();
//        public bool IsFirst = false;
//        public void AddJoint(Spline preSpline, PointD currentPoint)
//        {
//            if (preSpline == null)
//            {
//                StartControlPoint = StartPoint = EndControlPoint = EndPoint = currentPoint;
//                IsFirst = true;
//            }
//            else
//            {
//                if (preSpline.IsFirst)
//                {
//                    StartControlPoint = preSpline.StartControlPoint;
//                    StartPoint = preSpline.StartPoint;
//                }
//                else
//                {
//                    preSpline.EndControlPoint = currentPoint;
//                    preSpline.GenerateSamplePoints();
//                    StartControlPoint = preSpline.StartPoint;
//                    StartPoint = preSpline.EndPoint;
//                }
//                EndPoint = EndControlPoint = currentPoint;
//                GenerateSamplePoints();
//            }
//        }
//        public void GenerateSamplePoints()
//        {
//            double step = 1d / (GeneratePointsCountBetween2SamplePoints + 1), sum = 0;
//            controlPoints.Clear();
//            for (int i = 0; i <= GeneratePointsCountBetween2SamplePoints; i++)
//            {
//                controlPoints.Add(GenerateSimulatePoints(sum, StartControlPoint, StartPoint, EndControlPoint, EndPoint));
//                sum += step;
//            }
//            controlPoints.Add(EndPoint);
//        }
//        PointD GenerateSimulatePoints(double u, PointD startCtrlpt, PointD startpt, PointD endCtrlpt, PointD endpt)
//        {
//            double s = (1 - Tension) / 2;
//            return new PointD(calculateAxisCoordinate(startCtrlpt.X, startpt.X, endCtrlpt.X, endpt.X, s, u),
//                calculateAxisCoordinate(startCtrlpt.Y, startpt.Y, endCtrlpt.Y, endpt.Y, s, u));
//        }
//        static double calculateAxisCoordinate(double a, double b, double c, double d, double s, double u)
//        {
//            return a * (2 * s * u * u - s * u * u * u - s * u)
//                + b * ((2 - s) * u * u * u + (s - 3) * u * u + 1)
//                + c * s * u * u * (u - 1)
//                + d * ((s - 2) * u * u * u + (3 - 2 * s) * u * u + s * u);
//        }
//        public static PointD[] GetSamplePoints(IEnumerable<PointD> pts, int interval = 1, double tension = 0)
//        {
//            List<Spline> sps = new List<Spline>();
//            foreach (PointD item in pts)
//            {
//                Spline sp = new Spline()
//                {
//                    GeneratePointsCountBetween2SamplePoints = interval,
//                    Tension = tension,
//                };
//                sp.AddJoint(sps.Count == 0 ? null : sps[sps.Count - 1], item);
//                sps.Add(sp);
//            }
//            List<PointD> res = new List<PointD>();
//            foreach (Spline item in sps)
//            {
//                if (item.IsFirst) continue;
//                foreach (PointD pt in item.controlPoints)
//                {
//                    if (res.Contains(pt)) continue;
//                    res.Add(pt);
//                }
//            }
//            return res.ToArray();
//        }
//    }
//}
